#include "camera.h"
#include <QDebug>

Camera::Camera(QWidget *parent, QString sn, QString ip, QString mac)
	: QWidget(parent)
{
	ui.setupUi(this);

    ui.groupBox->setTitle(QString("SN: ") + sn);
    ui.ip->setText(ip);
    ui.mac->setText(mac);
    ui.ip->setEnabled(false);
    ui.mac->setEnabled(false);
    ui.btn_activate->setStyleSheet("background:rgb(255,0,0)");
    cam_sn = sn;
}

Camera::~Camera()
{
}

void Camera::deactive(void)
{
    qDebug() << "Camera: " << cam_sn << " deactivated";
    ui.btn_activate->setStyleSheet("background:rgb(255,0,0)");
    ui.btn_activate->setText("Deactivated");
}

void Camera::get_cam_info(QString* sn, QString* ip, QString* mac)
{
    *sn = cam_sn;
    *ip = ui.ip->text();
    *mac = ui.mac->text();
}

void Camera::on_btn_activate_clicked()
{
    bool activate;
    if (ui.btn_activate->text() == QString("Deactivated")) {
        ui.btn_activate->setStyleSheet("background:rgb(0,255,0)");
        ui.btn_activate->setText("Activated");
        activate = true;
    }
    else {
        ui.btn_activate->setStyleSheet("background:rgb(255,0,0)");
        ui.btn_activate->setText("Deactivated");
        activate = false;
    }
    emit btn_activate_clicked(activate, cam_sn);
}

void Camera::mqtt_disconnect()
{
    ui.btn_activate->setStyleSheet("background:rgb(0,255,255)");
    ui.btn_activate->setText("Activate");
}